package controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import dao.TeamDao;
import dao.impl.TeamDaoImpl;
import service.TeamService;
import service.impl.TeamServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author CY
 * @date 2023/01/03 15:40
 **/
@WebServlet("/teamJudgeServlet")
public class TeamJudgeInServlet extends HttpServlet {
    TeamService service = new TeamServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        //Json解析
        final BufferedReader bufferedReader = new BufferedReader(req.getReader());
        String line = null;
        final StringBuilder json = new StringBuilder();
        while ((line = bufferedReader.readLine()) != null) {
            json.append(line);
        }
        final JSONObject jsonObject = JSON.parseObject(json.toString());
        int tid = jsonObject.getInteger("tid");
        int uid = jsonObject.getInteger("uid");
        int rid= jsonObject.getInteger("rid");

        JSONObject message = new JSONObject();
        TeamDao dao = new TeamDaoImpl();
        if (dao.isInTeam2(uid, tid)) {
            message.put("status", "0");
            message.put("Msg", "你已经在队伍中!!!");
        }else{
            message.put("status", "1");
            message.put("Msg", "没有在队伍中!!!");
        }
        resp.getWriter().write(message.toString());


    }
}